﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.Entity;
using System.Data.Entity.ModelConfiguration;
using YCMS.Domain.Entities;


namespace YCMS.Domain.Concrete
{
    public class EfDbContext : DbContext
    {
        public DbSet<Dock> Dock { get; set; }
        public DbSet<Member> Member { get; set; }


        protected override void OnModelCreating(DbModelBuilder modelBuilder)
        {
            modelBuilder.Configurations.Add(new DockConfiguration());
            modelBuilder.Configurations.Add(new MemberConfiguration());
            modelBuilder.Entity<Dock>()
                .HasMany(c => c.Members).WithMany(i => i.Docks)
                .Map(t => t.MapLeftKey("DockID").MapRightKey("MemberID")
                    .ToTable("MemberDock"));
            modelBuilder.Entity<Member>()
                .HasMany(c => c.Docks).WithMany(i => i.Members)
                .Map(t => t.MapLeftKey("MemberID").MapRightKey("DockID")
                    .ToTable("MemberDock"));
                
                
            base.OnModelCreating(modelBuilder);
        }

    }

    public class DockConfiguration : EntityTypeConfiguration<Dock>
    {
        public DockConfiguration()
            : base()
        {
            ToTable("Dock");
            
        }
    }

    public class MemberConfiguration : EntityTypeConfiguration<Member>
    {
        public MemberConfiguration()
            : base()
        {
            ToTable("Member");
        }
    }
}
